package com.baijing.springbootstarterdata.dao;

import com.baijing.springbootstarterdata.domain.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;

import java.util.List;

//rest-date设置
@RepositoryRestResource(path = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {
    //data-jpa测试
    List<Person> findByAddress(String address);

    Person findByNameAndAddress(String name, String address);

    @Query("select p from Person p where p.name= :name and p.address = :address")
    Person withNameAndAddressQuery(@Param("name") String name, @Param("address") String address);

    Person withNameAndAddressNamedQuery(String name, String address);

    //data-rest设置
    //http://127.0.0.1:8081/persons/search/nameStartsWith?name=alice100
    //http://127.0.0.1:8081/api/persons/search/nameStartsWith?name=alice100
    //http://127.0.0.1:8081/api/people/search/nameStartsWith?name=alice100
    @RestResource(path = "nameStartsWith", rel = "nameStartsWith")
    Person findByNameStartsWith(String name);
}
